<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
    <input v-model="parentMsg">
    <br>
    <ChildComponent v-bind:message="parentMsg"></ChildComponent>
    <Runoob></Runoob>
    <todo-list :items="todoItems"></todo-list>
    <p>
      {{ total }}
    </p>
    <button-counter v-on:increment="incrementTotal"></button-counter>
    <button-counter v-on:increment="incrementTotal"></button-counter>
    <p>当页面载入时,input元素自动获取焦点</p>
    <input v-focus>
  </div>
</template>

<script>
import ChildComponent from './components/ChildComponent.vue';
import HelloWorld from './components/HelloWorld.vue'
import TodoList from './components/TodoList.vue';
import ButtonCounter from './components/ButtonCounter.vue';

export default {
  name: 'App',
  components: {
    ChildComponent,
    HelloWorld,
    TodoList,
    ButtonCounter,
  },
  // 注册局部自定义指令
  directives: {
    focus: {
      // 指令的定义
      mounted(el) {
        el.focus()
      }
    }
  },
  data() {
    return {
      parentMsg: '父组件内容',
      total: 0,
      todoItems: [
        { id: 1, name: 'Runoob' },
        { id: 2, name: 'Google' },
        { id: 3, name: 'Taobao' }
      ]
    }
  },
  methods: {
    incrementTotal() {
      this.total += 1;
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>